﻿// TextWriterExtensions.cs
//
// Copyright 2008-2011 by Burt Harris
// Licensed under the Microsoft Public License (Ms-PL)
// See: http://www.codeplex.com/yaml/license
//

namespace YaTools.Yaml
{
    using System.IO;
    using System.Diagnostics.Contracts;

    public static class TextWriterExtensions
    {
        private static readonly char[] Spaces = new string(Unicode.Space, 128).ToCharArray();

        public static void WriteSpaces(this TextWriter writer, int count)
        {
            Contract.Requires(writer != null);
            Contract.Requires(count >= 0);

            while (count > 0)
            {
                if (count <= Spaces.Length)
                {
                    writer.Write(Spaces, 0, count);
                    break;
                }
                writer.Write(Spaces);
                count -= Spaces.Length;
            }
        }

        public static void IndentLine(this TextWriter writer, int count)
        {
            Contract.Requires(writer != null);
            Contract.Requires(count >= 0);
            writer.WriteSpaces(count);
        }
    }
}